<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="model.Employee" %>
<!-- meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!-- css -->
<link href="style.css" media="all" rel="stylesheet" type="text/css" />
<!-- js -->
<script src="" type="text/javascript"></script>
<%
//昇順・降順用のデータ
String sort_employee_no = request.getParameter("employee_no");
String join_date_from = request.getParameter("join_date_from");
String join_date_to = request.getParameter("join_date_to");
if(sort_employee_no == null){
	sort_employee_no = "";
}
if(join_date_from == null){
	join_date_from = "";
}
if(join_date_to == null){
	join_date_to = "";
}
// メンバー一覧表示用のテーブル
String tableHTML = "<table border>";
tableHTML +="<th>社員番号<a href= \"/NEMS/Search?employee_no=" + sort_employee_no + "&sex=" + request.getParameter("sex") + "&section=" + request.getParameter("section") + "&join_date_from=" + join_date_from + "&join_date_to=" + join_date_to + "&action_id=1\">▲</a>"
	+ "<a href= \"/NEMS/Search?employee_no=" + sort_employee_no + "&sex=" + request.getParameter("sex") + "&section=" + request.getParameter("section") + "&join_date_from=" + join_date_from + "&join_date_to=" + join_date_to + "&action_id=2\">▼</a></th>"
    + "<th>名前</th>"
    + "<th>性別</th>"
    + "<th>入社年月日<a href= \"/NEMS/Search?employee_no=" + sort_employee_no + "&sex=" + request.getParameter("sex") + "&section=" + request.getParameter("section") + "&join_date_from=" + join_date_from + "&join_date_to=" + join_date_to + "&action_id=3\">▲</a>"
    + "<a href= \"/NEMS/Search?employee_no=" + sort_employee_no + "&sex=" + request.getParameter("sex") + "&section=" + request.getParameter("section") + "&join_date_from=" + join_date_from + "&join_date_to=" + join_date_to + "&action_id=4\">▼</a></th>"
    + "<th>部門</th>"
    + "<th>メールアドレス</th>"
    + "<th colspan=\"3\">操作</th>";
// 取得された各結果に対しての処理
ArrayList<Employee> employees = new ArrayList<Employee>();
employees = (ArrayList<Employee>) request.getAttribute("employees");
int record_count = employees.size();
for(int i = 0;i < record_count; i++){
	Employee employee = employees.get(i);
    String employee_no = employee.employee_no; // 社員番号を取得
    String first_name = employee.first_name; // 社員苗字を取得
    String last_name = employee.last_name; // 社員名前を取得
    String sex = employee.sex; // 性別を取得
    String join_date = employee.join_date; // 性別を取得
    String section = employee.section; // 性別を取得
    String e_mail = employee.mail; // 性別を取得
    String mailto = "\"mailto:";
    String detail = "\"detail\"";
    String update = "\"update\"";
    String delete = "\"delete\"";
    String post = "\"post\"";
    String URL_Detail = "/NEMS/SearchDetail";
    String URL_Update = "/NEMS/UpdateInput";
    String URL_Delete = "/NEMS/DeleteConfirmation";
    // 文字コードを EUC_JP からUnicode へ変換
    //name = new String(name.getBytes("8859_1"), "EUC_JP");
    //kana = new String(kana.getBytes("8859_1"), "EUC_JP");
    // テーブル用HTMLを作成
    tableHTML += "<tr><td align=\"right\">" + employee_no + "</td>\n"
              + "<td>" + first_name + last_name + "</td>\n"
              + "<td>" + sex + "</td>\n"
              + "<td align=\"right\">" + join_date + "</td>\n"
              + "<td>" + section + "</td>\n"
              + "<td><a href=" + mailto + e_mail + "\">" + e_mail + "</a></td>\n"
              + "<td><a href=" + URL_Detail + "?employee_no=" + employee_no + ">詳細</a></td>\n"
              + "<td><a href=" + URL_Update + "?employee_no=" + employee_no + ">更新</a></td>\n"
              + "<td><a href=" + URL_Delete + "?employee_no=" + employee_no + ">削除</a></td>\n";
}
String tableCOUNT =  "　全" + record_count + "件";
tableHTML += "</table>";
%>
<html>
<head><title>NEMS</title></head>
<body>
<h1>NEMS 【NJK Employee Management System】</h1>
<a href="/NEMS/Menu">メニューへ戻る</a><div align="right"><a href="/NEMS/Login">ログアウト</a></div>
<div align="right"><%=session.getAttribute("FullName")%>さん</div>
<h2>社員情報検索　一覧</h2>
<form method="get" action="/NEMS/Search" Accept-charset="UTF-8">
　検索条件
<table border>
<tr>
<th>社員番号</th>
<td><input type="text" name="employee_no" size="20" maxlength="5" value=<% if (request.getParameter("employee_no") != null) { %><%=request.getParameter("employee_no")%><% } %>></td>
<th>性別</th>
<td><SELECT name="sex">
<OPTION value="null" <% if (request.getParameter("sex") == null) { %>selected<% } %>></OPTION>
<OPTION value="1" <% if ("1".equals(request.getParameter("sex"))) { %>selected<% } %>>男性</OPTION>
<OPTION value="2" <% if ("2".equals(request.getParameter("sex"))) { %>selected<% } %>>女性</OPTION>
</SELECT>
</td>
<th>部門</th>
<td><SELECT name="section">
<OPTION value="null"<% if (request.getParameter("section") == null) { %>selected<% } %>></OPTION>
<OPTION value="BS1" <% if ("BS1".equals(request.getParameter("section"))) { %>selected<% } %>>BS1</OPTION>
<OPTION value="BS2" <% if ("BS2".equals(request.getParameter("section"))) { %>selected<% } %>>BS2</OPTION>
<OPTION value="BS3" <% if ("BS3".equals(request.getParameter("section"))) { %>selected<% } %>>BS3</OPTION>
<OPTION value="BS4" <% if ("BS4".equals(request.getParameter("section"))) { %>selected<% } %>>BS4</OPTION>
<OPTION value="ES1" <% if ("ES1".equals(request.getParameter("section"))) { %>selected<% } %>>ES1</OPTION>
<OPTION value="ES2" <% if ("ES2".equals(request.getParameter("section"))) { %>selected<% } %>>ES2</OPTION>
<OPTION value="ES3" <% if ("ES3".equals(request.getParameter("section"))) { %>selected<% } %>>ES3</OPTION>
<OPTION value="ES4" <% if ("ES4".equals(request.getParameter("section"))) { %>selected<% } %>>ES4</OPTION>
<OPTION value="SS1" <% if ("SS1".equals(request.getParameter("section"))) { %>selected<% } %>>SS1</OPTION>
<OPTION value="SS2" <% if ("SS2".equals(request.getParameter("section"))) { %>selected<% } %>>SS2</OPTION>
<OPTION value="SS3" <% if ("SS3".equals(request.getParameter("section"))) { %>selected<% } %>>SS3</OPTION>
<OPTION value="SS4" <% if ("SS4".equals(request.getParameter("section"))) { %>selected<% } %>>SS4</OPTION>
</SELECT>
</td>
</tr>
<tr>
<th>入社年月日(From)</th>
<td><input type="text" name="join_date_from" size="20" maxlength="8" value=<% if (request.getParameter("join_date_from") != null) { %><%=request.getParameter("join_date_from")%><% } %>></td>
<th>入社年月日(To)</th>
<td><input type="text" name="join_date_to" size="20" maxlength="8" value=<% if (request.getParameter("join_date_to") != null) { %><%=request.getParameter("join_date_to")%><% } %>></td>
</tr>
</table>
<div align="right"><input type="submit" name="search_again" value="検索"></div>
<input type="hidden" name="action_id" value="1">


<%= tableCOUNT %>
<%= tableHTML %>
</form>
</body>
</html>